package net.jalbum.filters.arty.effects;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;
import java.awt.image.DataBuffer;
import java.util.Map;
import se.datadosen.util.Stopwatch;

/**
 *
 * @author Sarah Schölzel 
 */
public class SunflowerFilter extends ArtySupport {

    public SunflowerFilter() {
    }

    @Override
    public String getName() {
        return "Sunflower";
    }

    @Override
    public String getDescription() {
        return "effect like the Brannin filter in Instagram";
    }

    @Override
    public BufferedImage filter(BufferedImage bi, Map map) {
        return filter(bi);
    }

    @Override
    public BufferedImage filter(BufferedImage bi) {
        bi = super.filter(bi);

        BufferedImage dstImg;
//Stopwatch sw = new Stopwatch();
//sw.start();
        //graystyle
        BufferedImage tmp = getGrayScale(bi);
//sw.printDelta("getGrayScale");
        //saturation = -30
        bi = applySaturation(bi, -30);
//sw.printDelta("applySaturation");

        //blending Mode Overlay, 70%
        Graphics2D g2 = bi.createGraphics();
        g2.drawImage(bi, 0, 0, null);
//sw.printDelta("drawImage");
        g2.setComposite(BlendComposite.getInstance(BlendComposite.BlendingMode.OVERLAY, 0.7f));
        g2.drawImage(tmp, 0, 0, bi.getWidth(), bi.getHeight(), null);
//sw.printDelta("drawImage");

        // brightness and contrast
        dstImg = applyBrightnessAndContrast(bi, -10, 20);
//sw.printDelta("applyBrightnessAndContrast");

        //saturation
        dstImg = applySaturation(dstImg, 30);
//sw.printDelta("applySaturation");
        //Copy of ColorLayer
        BufferedImage tmp2 = new BufferedImage(bi.getWidth(), bi.getHeight(), bi.getType());
        g2 = tmp2.createGraphics();
        g2.setColor(new Color(220, 210, 170));
        g2.fill(new Rectangle(0, 0, bi.getWidth(), bi.getHeight()));

//sw.printDelta("Copy of ColorLayer");        
        //Blending mode: Overlay, 40%
        Graphics2D g = dstImg.createGraphics();
        g.drawImage(dstImg, 0, 0, null);
        g.setComposite(BlendComposite.getInstance(BlendComposite.BlendingMode.OVERLAY, 0.3f));
        g.drawImage(tmp2, 0, 0, bi.getWidth(), bi.getHeight(), null);

//sw.printDelta("Blending mode: Overlay, 40%");             
        return dstImg;
    }
}
